package com.vishnu.main;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.vishnu.pojo.Employee;
import com.vishnu.pojo.Product;

public class StoreEmployeeData {

	public static void main(String[] args)throws Exception {
		Configuration cfg=new Configuration();
		System.out.println("--before configure() method.....");
		    cfg.configure("hib.cfg.xml");
		    System.out.println("--after configure() method.....");
		    
		    SessionFactory sf=cfg.buildSessionFactory();
		  System.out.println("--after buildSessionfactory() method.....");
		    Session hsession=sf.openSession();
		    System.out.println("--after opensession() method.....");
		    Transaction transac=hsession.beginTransaction();
		    System.out.println("--after beginTransaction() method.....");
		    
		    Employee employee=new Employee();
	//	    employee.setEmployeeId(1);
		    employee.setEmployeeName("raju");
		    employee.setEmployeeAddress("bangl");
		    employee.setEmployeeSalary(98334.);
/*		    product.setProductId(4);
		    product.setProductName("vinu");
		    product.setProductPrice(7000.);*/
		    
	//	    hsession.saveOrUpdate(employee1);
		    
		    hsession.save(employee);
		    
		    
//		    System.out.println("serializable object :"+o.getClass());
//		    System.out.println("content of serializable object="+(o).toString());
            
/*	    System.out.println("eid="+product.getProductId());
	    System.out.println("ename="+product.getProductName());
	    System.out.println("esalary="+product.getProductPrice());*/
	//	    System.out.println("employee="+employee);
		    
		    if(employee!=null){
		//    	Employee employee=(Employee)o;
		    System.out.println("eid="+employee.getEmployeeId());
		 
		    System.out.println("ename="+employee.getEmployeeName());
		    System.out.println("esalary="+employee.getEmployeeSalary());
		    System.out.println("hsession contains employee1:"+hsession.contains(employee));
		    }else{
		    	System.out.println("No records are available...");
		    	
		    }
		    transac.commit();
		    hsession.close();
		    sf.close();
	}
	
}
